/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Andrés Felipe
 */
@Entity
@Table(name = "\"javeriana.sc.cc\".\"t_RequestXproduct\"")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "RequestXproduct.findAll", query = "SELECT r FROM RequestXproduct r"),
    @NamedQuery(name = "RequestXproduct.findByIdrequest", query = "SELECT r FROM RequestXproduct r WHERE r.requestXproductPK.idrequest = :idrequest"),
    @NamedQuery(name = "RequestXproduct.findByProductid", query = "SELECT r FROM RequestXproduct r WHERE r.requestXproductPK.productid = :productid"),
    @NamedQuery(name = "RequestXproduct.findByQuantity", query = "SELECT r FROM RequestXproduct r WHERE r.quantity = :quantity")})
public class RequestXproduct implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected RequestXproductPK requestXproductPK;
    @Basic(optional = false)
    @NotNull
    @Column(name = "quantity")
    private int quantity;
    @JoinColumn(name = "productid", referencedColumnName = "idproduct", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Product product;
    @JoinColumn(name = "idrequest", referencedColumnName = "idrequest", insertable = false, updatable = false)
    @ManyToOne(optional = false,cascade = CascadeType.REMOVE)
    private CustomerRequest customerRequest;

    public RequestXproduct() {
    }

    public RequestXproduct(RequestXproductPK requestXproductPK) {
        this.requestXproductPK = requestXproductPK;
    }

    public RequestXproduct(RequestXproductPK requestXproductPK, int quantity) {
        this.requestXproductPK = requestXproductPK;
        this.quantity = quantity;
    }

    public RequestXproduct(int idrequest, int productid) {
        this.requestXproductPK = new RequestXproductPK(idrequest, productid);
    }

    public RequestXproductPK getRequestXproductPK() {
        return requestXproductPK;
    }

    public void setRequestXproductPK(RequestXproductPK requestXproductPK) {
        this.requestXproductPK = requestXproductPK;
    }

    public int getQuantity() {
        return quantity;
    }

    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }

    public Product getProduct() {
        return product;
    }

    public void setProduct(Product product) {
        this.product = product;
    }

    public CustomerRequest getCustomerRequest() {
        return customerRequest;
    }

    public void setCustomerRequest(CustomerRequest customerRequest) {
        this.customerRequest = customerRequest;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (requestXproductPK != null ? requestXproductPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof RequestXproduct)) {
            return false;
        }
        RequestXproduct other = (RequestXproduct) object;
        if ((this.requestXproductPK == null && other.requestXproductPK != null) || (this.requestXproductPK != null && !this.requestXproductPK.equals(other.requestXproductPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entities.RequestXproduct[ requestXproductPK=" + requestXproductPK + " ]";
    }
    
}
